package com.aaa.shuke2024.service.impl;

import com.aaa.shuke2024.entity.AlarmLimit;
import com.aaa.shuke2024.dao.AlarmLimitDao;
import com.aaa.shuke2024.service.AlarmLimitService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 告警管理表(AlarmLimit)表服务实现类
 *
 * @author teacherChen
 * @since 2024-12-04 16:10:59
 */
@Service("alarmLimitService")
public class AlarmLimitServiceImpl implements AlarmLimitService {
    @Resource
    private AlarmLimitDao alarmLimitDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public AlarmLimit queryById(Integer id) {
        return this.alarmLimitDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param alarmLimit 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<AlarmLimit> queryByPage(AlarmLimit alarmLimit, PageRequest pageRequest) {
        long total = this.alarmLimitDao.count(alarmLimit);
        return new PageImpl<>(this.alarmLimitDao.queryAllByLimit(alarmLimit, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param alarmLimit 实例对象
     * @return 实例对象
     */
    @Override
    public AlarmLimit insert(AlarmLimit alarmLimit) {
        this.alarmLimitDao.insert(alarmLimit);
        return alarmLimit;
    }

    /**
     * 修改数据
     *
     * @param alarmLimit 实例对象
     * @return 实例对象
     */
    @Override
    public AlarmLimit update(AlarmLimit alarmLimit) {
        this.alarmLimitDao.update(alarmLimit);
        return this.queryById(alarmLimit.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.alarmLimitDao.deleteById(id) > 0;
    }

    @Override
    public AlarmLimit queryByIp(String serverIp) {
        return alarmLimitDao.queryByIp(serverIp);
    }
}
